<template>
  <Pageskeleton v-if="skeletonflag" ></Pageskeleton>
  <view v-else class="box">
   
  <emplty v-if="!orderlist.length"></emplty>
    <view v-else class="matron" @click="Onto(`/pages/order/order?order=${item.serial}`)"  v-for="item in orderlist" :key="item.serial">
      <view class="order_serial"><span style="color: rgba(0, 0, 0, 0.7);">订单编号:</span>{{item.serial}}</view>
      <view class="item">
        <img class="h1-img" style="position: absolute;" src="/static/show.png" alt="">
        <img class="h1-img" :src="item.default_img" alt="">
      <view class="text">
        <view class="text_name">{{item.name}}</view>
        <view class="text_start"><span style="color: rgba(0, 0, 0, 0.8);">开始日期:</span>{{item.date_start}}</view>
        <view class="text_end"><span style="color: rgba(0, 0, 0, 0.8);">结束日期:</span>{{item.date_end}}</view>
      </view>
      </view>
      <view class="order_price">
        <text class="price_info">合计:￥ </text>
        <text class="price_text">{{item.price}}</text>
       
      </view>
      <view  v-if="!item.is_pay"  class="Button">
        <view class="bc">取消订单</view>
        <view class="bc" @click.stop="Onto(`/pages/order/order?order=${item.serial}`)">去支付</view>
      </view>
      <view  v-else-if="!item.is_sever"  class="Button">
        <view class="bc">取消订单</view>
        <view class="bc"  @click.stop="Onsever(item.serial)">确认服务</view>
      </view>

      <view v-else-if="!item.is_comment"  class="Button">
       <view class="bc" @click.stop="Onto(`/pages/comment/comment?serial=${item.serial}`)">立即评价</view>
    
      </view>
      <view v-else  class="Button">
        <view class="bc" @click.stop="onto(`/pages/detail/detail?id=${item.matron_id}`)">再来一单</view>
        
      </view>

    </view>
  </view>
</template>

<script setup lang="ts">
  import {ref} from 'vue'
import {http} from '@/utlis/http.ts'
import {onShow} from '@dcloudio/uni-app'
  import Pageskeleton from './components/Pageskeleton.vue'
  import emplty from '@/components/emplty.vue'
  const skeletonflag = ref(true)
  const Onto=(e)=>{
    uni.navigateTo({ url: e })
  }
  const Onsever=(serial)=>{
    console.log('serial',serial)
    uni.request({
      url: 'order/sever/',
      data: {
        serial:serial,
        type:true
      },
      method:'POST',
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        'X-Requested-With': 'XMLHttpRequest'
      },
   
	// #ifdef H5
		withCredentials: true,
	// #endif
  
      sslVerify: true,
      success: ({ data, statusCode, header }) => {
        if(data.code==200 || data.code==0){
          uni.showToast({
            title: '确认成功',
            icon: 'success',
            mask: true
          })
      uni.request({
  url: 'order/list/',
  data: {},
  header: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    'X-Requested-With': 'XMLHttpRequest'
  },
  
  method: 'POST',
  sslVerify: true,
  success: ({ data, statusCode, header }) => {
    console.log(data)
    orderlist.value=data['data']
    console.log('detail_list',orderlist.value)
  },
  fail: (error) => {
    console.log('网络错误')
    uni.showToast({
      title: '网络错误',
      icon: 'error',
      mask: true
    })
  }
})
        }
        else{
          uni.showToast({
            title: '确认失败',
            icon: 'error',
            mask: true
          })
        }
      },
      fail: (error) => {}
    })
  }
  const NaverTO=(e)=>{
    console.log('ki',)
 
  }
  const orderlist=ref([
])

onShow(()=>{
  uni.request({
  url: 'order/list/',
  data: {},
  header: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    'X-Requested-With': 'XMLHttpRequest'
  },
  
  method: 'POST',
  sslVerify: true,
  success: ({ data, statusCode, header }) => {
   if(data.code == 0 || data.code ==200){
    orderlist.value=data['data']
    console.log('detail_list',data)
   }
   else{
    orderlist.value = []
   }
    skeletonflag.value = false
  },
  fail: (error) => {
    console.log('网络错误')
    uni.showToast({
      title: '网络错误',
      icon: 'error',
      mask: true
    })
  }
})
})
</script>
<style lang="scss">
  .emplty{
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    title{
      color: #adaaaa;
      font-size: 28px;
      letter-spacing: 0.1em;
    }
  }
page{
  background-color: rgba(231, 230, 227,0.3);
  padding: 0;
  margin: 0;

}
.box{
  margin: 0;
  width: 100%;
 
  .matron{
   
    align-items: center;
    border: 2px rgba(0, 0, 0, 0.7);
    box-shadow: 1px 2px 3px -2px rgba(0, 0, 0, 0.4);
   
    margin: 5px;

    border-radius: 3px;
    margin-bottom: 9px;
    background-color: rgb(255, 255, 255);
    .order_serial{
      padding-top: 8px;
      padding-bottom: 8px;
      padding-left: 6px;
      font-size: 14px;
      font-weight: 350;
      color: #adaaaa;
      border-bottom: 0.5px solid rgba(0, 0, 0, 0.3);
    }
    .Button{
      display: flex;
      justify-content: flex-end;
      align-items: center;
      text-align: center;
      padding: 0;
      padding-top: 8px;
      padding-bottom: 8px;
      margin-bottom: 5px;
      border-top: 0.5px solid rgba(0, 0, 0, 0.3);
      .over_order{
        /* margin: 5px; */
        color: #adaaaa;
        margin-right: 10px;
        letter-spacing: 0.099em;
        font-size: 13px;
      }
      
      .bc{
        display: inline-block;
        width: 90px;
        height: 30px;
        font-size: 12px;
        line-height: 30px;
        margin-left: 6px;
        margin-right: 6px;
        /* border: 0.5px solid #adaaaa; */
        border-radius: 5px;
        box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
      }
      .bc:active{
        background-color:rgb(136, 77, 0);
      }
      .bc:nth-child(1){
        background-color: #fff;
      }
      .bc:nth-child(2){
        color: #fff;
        /* background-color: rgb(249, 173, 73); */
        background-color: #26e6bc;
      }
    }
    .order_price{
      display: flex;
      justify-content: flex-end;
      align-items: first baseline;
      margin: 4px;
      color: #adaaaa;
      font-weight: 360;
      letter-spacing: 0.01em;
      .price_info{
        font-size: 13px;
       color: rgba(0, 0, 0, 0.8);
      }
      .price_text{
        margin-left: -2px;
        margin-right: 6px;
        font-size: 18px;
        
        color:red
      }
    }
  }
  .item{
    display: flex;
    margin: 5px;
    margin-top: 10px;
    
    .h1-img{
      
      width: 5rem;
      height: 5rem;
      border-radius: 5px;

    }
    .text{
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      letter-spacing: 0.01em;
      margin-left:10px ;
      font-size: 14px;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.5);
      .text_name{
        letter-spacing: 0.09em;
        color: rgba(0, 0, 0, 0.7);
        font-size: 16px;
        font-weight: 600;
      }
    }
    #title{
      font-size: 13px;
    }
    #price{
      color: red;
    }
  }
}
</style>
